﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WinForm2
{
    class DBhelp
    {
        private static string conString = "server=.;database=SchoolDB;uid=sa;pwd=123456";
        public static DataTable GetDataTable(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);
            SqlDataAdapter adapter = new SqlDataAdapter(sql, sqlConnection);
            sqlConnection.Open();
            DataTable dt = new DataTable(); //存储数据库信息
            adapter.Fill(dt); //输出
            return dt;
        }

        public static int Update(string sql)
        {

            SqlConnection sqlConnection = new SqlConnection(conString);
            SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
            sqlConnection.Open();
            return sqlCommand.ExecuteNonQuery();
        }
    }
}
